$().ready(function() {
	
});

function process(){
	var beginDate = $("#beginDate").val();
	var endDate = $("#endDate").val();
	
	//Count progress bar
	var trnDailyCount = setInterval(progressBar,100); 
	$("#statusProcess").text("Processing");
	$.ajax({
		url : '/dfshc/trn/calculate', 
		type : "post",
		data : {
			beginDate:beginDate,
			endDate:endDate
		},
		success: function(data){
			
			clearInterval(trnDailyCount);
			
			console.log(data);
			var json = JSON.parse(data);
			
	
			
			var size = json.trnSize;
			var doneSize = json.trnSizeDone;
			var issueSize = json.trnSizeIssue;
			var status = json.trnProcessStatus;			
			
			$("#statusProcess").text(status);
//			$("#processNumber").text(doneSize+'/'+size+' (Issue trn is '+issueSize+')');
			$("#processNumber").text('100%');
			$('#issueTrn tr:last').after('<tr>'+
					'<th>No</th>'+
					'<th>Doctor Code</th>'+
					'<th>Line no.</th>'+
					'<th>Invoice no.</th>'+
					'<th>Issue reason</th>'+
					'</tr>');
			
			var issueTrnList = json.trnIssue;
			
			for (var i = 0; i < issueTrnList.length; i++) { 
			    
				$('#issueTrn tr:last').after('<tr>'+
						'<td>'+(i+1)+'</td>'+
						'<td>'+issueTrnList[i].doctorCode+'</td>'+
						'<td>'+issueTrnList[i].lineNo+'</td>'+
						'<td>'+issueTrnList[i].invNo+'</td>'+
						'<td>'+issueTrnList[i].reason+'</td>'+
					'</tr>');
			}
		}
	})
}

function progressBar(){
	$.ajax({
		url : '/dfshc/trn/calculate_processing', 
		type : "post",
		success: function(data){
			$("#processNumber").text(data);
		}
	});
	
}